package company_tencent.f;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class T4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        LinkedList<Integer> consistentList = new LinkedList<>();
        HashSet<Integer> enough = new HashSet<>();
        int min = Integer.MAX_VALUE;
        while (n > 0) {
            n--;
            int curr = sc.nextInt();
            if (!consistentList.isEmpty() && (consistentList.peekFirst().equals(curr))) {
                consistentList.pop();
                consistentList.add(curr);
            } else {
                if (curr != 0) {
                    enough.add(curr);
                }
                consistentList.add(curr);
            }
            while (!consistentList.isEmpty() && (consistentList.peekFirst().equals(0)||consistentList.lastIndexOf(consistentList.peekFirst()) != 0)) {
                consistentList.pop();
            }
            if (enough.size() == m) {
                if (min > consistentList.size()) {
                    min = consistentList.size();
                }
            }
        }
        if (min == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(min);
        }
    }
}
